$(function(){
      $("#addSystem").validate({
       rules: {
         systemName: {
           required: true,
           maxlength: 32
         },
         systemDesc: {
           required: true,
           maxlength: 32
         }
       },
       messages: {
         systemName: {
           required: "请输入系统名",
           maxlength: "最多32个字符"
         },
         systemDesc: {
            required: "请输入系统名",
           maxlength: "最多32个字符"
         }
       }
   });

    $("#updateSystem").validate({
          rules: {
            systemName: {
              required: true,
              maxlength: 32
            },
            systemDesc: {
              required: true,
              maxlength: 32
            }
          },
          messages: {
            systemName: {
              required: "请输入系统名",
              maxlength: "最多32个字符"
            },
            systemDesc: {
               required: "请输入系统描述",
              maxlength: "最多32个字符"
            }
          }
      });
});

function saveSystem(){
   if($("#addSystem").valid()){
      $.ajax({
         url:$("#addSystem").attr("action"),
         data:$("#addSystem").serialize(),
         dataType:"json",
         success:function(data){
            if(data.returnCode == '0000'){
              noticeMsg("成功",0,1);
            }else{
              noticeMsg(data.returnMsg==null?data.errorMsg:data.returnMsg,1);
            }
         },
         error:function(){
            noticeMsg("发生错误",1);
         }
      });
   }
}

function deleteSystem(id){
   if(id == ''){
      noticeMsg("id不可以为空");
      return;
   }
   if(confirm("确定删除这条记录")){
      $.ajax({
               url:"/system/delete/"+id,
               dataType:"json",
               success:function(data){
                  if(data.returnCode == '0000'){
                    noticeMsg("成功",0,1);
                  }else{
                    noticeMsg(data.returnMsg==null?data.errorMsg:data.returnMsg,1);
                  }
               },
               error:function(){
                  noticeMsg("发生错误",1);
               }
            });
   }
}

function editSystem(id){
if(id == ''){
      noticeMsg("id不可以为空");
      return;
   }

   $.ajax({
                  url:"/system/edit/"+id,
                  dataType:"json",
                  success:function(data){
                     if(data.returnCode == '0000'){
                       $("#updateSystem #systenName").val(data.systemName);
                       $("#updateSystem #id").val(data.id);
                       $("#updateSystem #systemDesc").val(data.systemDesc);
                       $("#updateModal").modal('show');
                     }else{
                       noticeMsg(data.returnMsg,1);
                     }
                  },
                  error:function(){
                     noticeMsg("发生错误",1);
                  }
    });
}


function updateSystem(){
   if($("#updateSystem").valid()){
      $.ajax({
         url:$("#updateSystem").attr("action"),
         data:$("#updateSystem").serialize(),
         dataType:"json",
         success:function(data){
            if(data.returnCode == '0000'){
              noticeMsg("成功",0,1);
            }else{
              noticeMsg(data.returnMsg,1);
            }
         },
         error:function(){
            noticeMsg("发生错误",1);
         }
      });
   }
}